package jwdt.xadmin.system.action;

import jwdt.common.action.BaseAction;
import jwdt.xadmin.system.bean.QXCD;
import jwdt.xadmin.system.service.CdManageService;

import com.ezerg.db.ext.PageUtil;
import com.ezerg.web.Form;
import com.ezerg.web.Module;
import com.ezerg.web.Page;
import com.ezerg.web.annotation.Controller;
import com.ezerg.web.annotation.RequestMapping;

@Controller("/xadmin/system")
public class CdManageAction extends BaseAction {
	
	CdManageService cdService = app.getBean("cdManageService");
	
	@RequestMapping("/selectCd")
	public Page doSelectCd(Form f, Module m) throws Exception {
		String sjcd = f.getString("sjcd", "");
		PageUtil pu = (PageUtil) f.copy2Class(PageUtil.class);
		return m.writePage(f, cdService.selectCdList(pu, sjcd).toJson());
	}
	
	@RequestMapping("/cdLeftTree")
	public Page doLeftTree(Form f, Module m)throws Exception {
		return m.jsonPage(f, cdService.cdLeftTree());
	}
	
	@RequestMapping("/selectOneCd")
	public Page doSelectOneCd(Form f, Module m) throws Exception {
		String cddm = f.getString("cddm");
		return m.jsonPage(f, cdService.selectOneCd(cddm));
	}
	
	@RequestMapping("/saveCd")
	public Page doSaveCd(Form f, Module m) throws Exception {
		int act = f.getInt("action");
		QXCD obj = (QXCD)f.copy2Class(QXCD.class);
		if(act == 1) {
			return m.writePage(f, cdService.addCd(obj));
		} else {
			String cddm = f.getString("cddm");
			return m.writePage(f, cdService.saveCd(cddm, obj));
		}
	}
	
	@RequestMapping("/delCd")
	public Page doDelType(Form f, Module m) throws Exception {
		String cddm = f.getString("cddm");
		return m.writePage(f, cdService.delCd(cddm));
	}

}
